﻿var datatable;// 定义一个全局的dataTable
var userCountByBrandChar;
var flowCountByBrandChar;
var userCountByModelChar;
var flowCountByModelChar;
var allUserCountByNetPieChar;
var lteUserCountByNetPieChar;
var otherUserCountByNetPieChar;
var lockUserCountByNetPieChar;
var allFlowCountByNetPieChar;
var lteFlowChar;
var otherFlowChar;
var lockFlowChar;
var d;
var param = new Object({
	init:function(){
			this.timeSize = ''
			this.beginDate = ''
			this.endDate = ''
			this.cityCode = ''
			this.terminalBrand = ''
			this.terminalModel = ''
	},
	setParam:function(){
		this.init()
		this.timeSize = $('input:radio[name="timeSize"]:checked').val();
		this.beginDate = $('#beginDate').val();
		this.endDate = $('#endDate').val();
		this.cityCode = $("#showArea").val();
		this.terminalBrand = $("#brandDiv").val();
		var localterminalModel=$("#modelDiv").val();
		if(localterminalModel=="全部"){
			localterminalModel="";//当没有点击品牌的时候，型号没有值，所以值会是全部
		}
		this.terminalModel = localterminalModel;
	}
});
$(function() {
	init();
	//联想下拉
//	$("#netYuan").combobox();
//	$("#terminalType").combobox();
//	$("#failureReason").combobox();
		
	//初始化table
	//getList();
	$('#table tbody').on('click', 'tr', function() {
		if ($(this).hasClass('selected')) {
			$(this).removeClass('selected');
		} else {
			datatable.$('tr.selected').removeClass('selected');
			$(this).addClass('selected');
		}
	});
	
	//初始化图表
	userCountByBrandChar = echarts.init(document.getElementById('userCountByBrandCharDiv'));
	flowCountByBrandChar = echarts.init(document.getElementById('flowCountByBrandCharDiv'));
	userCountByModelChar = echarts.init(document.getElementById('userCountByModelCharDiv'));
	flowCountByModelChar = echarts.init(document.getElementById('flowCountByModelCharDiv'));
	
	allUserCountByNetPieChar= echarts.init(document.getElementById('allUserCountByNetCharDiv'));
	lteUserCountByNetPieChar= echarts.init(document.getElementById('lteUserCountByNetCharDiv'));
	otherUserCountByNetPieChar= echarts.init(document.getElementById('otherUserCountByNetCharDiv'));
	lockUserCountByNetPieChar= echarts.init(document.getElementById('lockUserCountByNetCharDiv'));
	
	allFlowCountByNetPieChar= echarts.init(document.getElementById('allFlowCountByNetCharDiv'));
	lteFlowChar= echarts.init(document.getElementById('lteFlowDiv'));
	otherFlowChar= echarts.init(document.getElementById('otherFlowDiv'));
	lockFlowChar= echarts.init(document.getElementById('lockFlowDiv'));
//	otherFLowCountByNetPieChar= echarts.init(document.getElementById('otherFLowCountByNetCharDiv'));
//	lockFLowCountByNetPieChar= echarts.init(document.getElementById('lockFLowCountByNetCharDiv'));
	allUserCountByNetPieChar.on('click', function (param) {
        if($("#lteUserCountByNetCharDiv").is(":hidden")){
        	 $("#lteUserCountByNetCharDiv,#otherUserCountByNetCharDiv,#lockUserCountByNetCharDiv").show("slow");
        }else{
        	 $("#lteUserCountByNetCharDiv,#otherUserCountByNetCharDiv,#lockUserCountByNetCharDiv").hide("slow");
        }

});
	allFlowCountByNetPieChar.on('click', function (param) {
        if($("#lteFlowDiv").is(":hidden")){
        	 $("#lteFlowDiv,#otherFlowDiv,#lockFlowDiv").show("slow");
        }else{
        	$("#lteFlowDiv,#otherFlowDiv,#lockFlowDiv").hide("slow");
        }

});
	//getList();
})
function init(){
	showArearList("showArea");
	$("#brandDiv").jqxComboBox({promptText: "全部",width: 230,height: 25});
	$("#modelDiv").jqxComboBox({promptText: "全部",width: 230,height: 25});
		    var brandsource =
		    {
		        datatype: "json",
		        datafields: [
		            { name: 'value' },
		            { name: 'label' }
		        ],
		        url: "../../excavantionAnalysis/terminalAnalysis/getBrandList",
		        async: false
		    };
		    brand_data=new Array() ; 
		    var brandAdapter = new $.jqx.dataAdapter(brandsource);

		    $("#brandDiv").jqxComboBox(
		    { 
		    	source: brandAdapter, 
		    	promptText: "全部",
		    	displayMember: "value", 
		    	valueMember: "label", 
		    	width: 230, 
		    	height: 25,
		    	autoComplete: true,
		    	renderer: function (index, label, value) {
		    		
	                var item = brandAdapter.records[index];
	                
	                if (item != null) {

	                    var label = item.label ;
	                    brand_data[index]=item;
	                    return label;

	                }
	                	return "";


	            }
		    });
		    $("#brandDiv").val("all");
		    $("#brandDiv").on('change', function (event) {
		    	getModelList($(this).val());
		    });
	
}
function getModelList(brandId){
	var modelsource =
    {
        datatype: "json",
        datafields: [
            { name: 'terminal_model' },
            { name: 'terminal_model' }
        ],
        url: "../../excavantionAnalysis/terminalAnalysis/getModelList?brandId="+brandId,
        async: false
    };
	var modelAdapter = new $.jqx.dataAdapter(modelsource);

    // 信令类型名称
    $("#modelDiv").jqxComboBox(
    { 
    	source: modelAdapter, 
    	promptText: "全部",
    	displayMember: "terminal_model", 
    	valueMember: "terminal_model", 
    	width: 230, 
    	height: 25,
    	autoComplete: true
    });
    $("#modelDiv").val("");
}
/**
 * 查询方法
 */
function queryData(){
	//首先判断是查询哪个数据 是图表还是列表

	var tableDiv = $("#con");
	var charDiv = $("#pic");

	if (tableDiv.is(":hidden")) {
		charDiv.show();
		initUserCountbyBrandBarChar();
		initFlowCountbyBrandBarChar();
		initUserCountbyModelBarChar();
		initFlowCountbyModelBarChar();
		initAllUserCountbyNetPieChar();
		initLteUserCountbyNetPieChar();
		initOtherUserCountbyNetPieChar();
		initLockUserCountbyNetPieChar();
		initAllFlowCountbyNetPieChar();
		initLteFlowCountbyNetPieChar();
		initOtherFlowCountbyNetPieChar();
		initLockFlowCountbyNetPieChar();
	} else {
		charDiv.hide();
		getList();	
	}
	
}
function getList() {
	var beginDate = $("#beginDate").val();
	var endDate = $("#endDate").val();
	if(beginDate==""){
		alert("请选择开始时间！");
		return;
	}
	if(endDate==""){
		alert("请选择结束时间！");
		return;
	}
	
	var beginDate1 = new Date(beginDate.replace(/-/g,"/"));
	var endDate2 = new Date(endDate.replace(/-/g,"/"));
	if((beginDate1-endDate2)>0){
		alert("开始时间不能大于或等于结束时间！");
		return;
	}
	param.setParam();
	$("#table tbody tr").remove();
	if (datatable == undefined || datatable == "undefined" || datatable == null) {
	} else {
		datatable.fnDestroy();
	}
	datatable = $('#table')
			.dataTable(
					{
						"aoColumnDefs" : [ {
							sDefaultContent : '',
							aTargets : [ '_all' ]
						} ],
						"bPaginate" : true, // 翻页功能
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"bSort" : false, // 排序功能
						"bInfo" : true,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
						"sScrollX" : "100%",
						"sScrollXInner" : "110%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../../excavantionAnalysis/terminalAnalysis/getList",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$
									.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"param" : JSON.stringify(param)
										}, // 以json格式传递
										"success" : function(resp) {
											fnCallback(resp.pageDate);
											d = resp.allData;
										}
									});
						},
						columns : [
								{
									data : "report_date"
								},
								{
									data : "terminal_model"
								},
								{
									data : "terminal_brand"
								},
								{
									data : "terminal_type"
								},
								{
									data : "terminal_os"
								},
								{
									data : "user_count",
									
								},
								{
									data : "flow_count"
								},
								{
									data : "avg_flow_count"
								},
								{
									data : "tcp_success_rate"
								}, 
								{
									data : "dns_success_rate"
								},
								{
									data : "attach_success_rate"
								},
								
								{
									data : "tau_success_rate"
								},
								{
									data : "session_success_rate"
								},
								{
									data : "download_rate"
								}]

					});
}

function showPic() {

	var tab = $("#con");
	var pic = $("#pic");

	if (tab.is(":hidden")) {
		tab.show();
		pic.hide();
	} else {
			tab.hide();
			pic.show();
			initUserCountbyBrandBarChar();
			initFlowCountbyBrandBarChar();
			initUserCountbyModelBarChar();
			initFlowCountbyModelBarChar();
			initAllUserCountbyNetPieChar();
			initLteUserCountbyNetPieChar();
			initOtherUserCountbyNetPieChar();
			initLockUserCountbyNetPieChar();
			initAllFlowCountbyNetPieChar();
			initLteFlowCountbyNetPieChar();
			initOtherFlowCountbyNetPieChar();
			initLockFlowCountbyNetPieChar();
		
	}
}
/**
 * 按终端供应商获取用户数
 */
function initUserCountbyBrandBarChar() {
	// 查询
	param.setParam();
	userCountByBrandChar.clear();
	userCountByBrandChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getUserCountByBar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "terminalBrand"
			
		},
		success : function(data) {
			userCountByBrandChar.setOption(data, true);
			userCountByBrandChar.hideLoading();
		}
	});

}
/**
 * 按终端供应商获取流量数
 */
function initFlowCountbyBrandBarChar() {
	// 查询
	param.setParam();
	flowCountByBrandChar.clear();
	flowCountByBrandChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getFlowCountByBar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "terminalBrand"
		},
		success : function(data) {
			flowCountByBrandChar.setOption(data, true);
			flowCountByBrandChar.hideLoading();
		}
	});

}
/**
 * 按终端类型获取用户数
 */
function initUserCountbyModelBarChar() {
	// 查询
	param.setParam();
	userCountByModelChar.clear();
	userCountByModelChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getUserCountByBar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "terminalModel"
		},
		success : function(data) {
			userCountByModelChar.setOption(data, true);
			userCountByModelChar.hideLoading();
		}
	});

}
/**
 * 按终端类型获取流量数
 */
function initFlowCountbyModelBarChar() {
	// 查询
	param.setParam();
	flowCountByModelChar.clear();
	flowCountByModelChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getFlowCountByBar?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "terminalModel"
		},
		success : function(data) {
			flowCountByModelChar.setOption(data, true);
			flowCountByModelChar.hideLoading();
		}
	});

}
/**
 * 按网络类型获取用户数
 */
function initAllUserCountbyNetPieChar() {
	// 查询
	param.setParam();
	allUserCountByNetPieChar.clear();
	allUserCountByNetPieChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getAllCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "user_num"
		},
		success : function(data) {
			allUserCountByNetPieChar.setOption(data, true);
			allUserCountByNetPieChar.hideLoading();
		}
	});

}
/**
 * 按网络类型获取4G用户数
 */
function initLteUserCountbyNetPieChar() {
	// 查询
	param.setParam();
	lteUserCountByNetPieChar.clear();
	lteUserCountByNetPieChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getUserCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "1"
		},
		success : function(data) {
			lteUserCountByNetPieChar.setOption(data, true);
			lteUserCountByNetPieChar.hideLoading();
		}
	});

}
/**
 * 按网络类型获取3G用户数
 */
function initOtherUserCountbyNetPieChar() {
	// 查询
	param.setParam();
	otherUserCountByNetPieChar.clear();
	otherUserCountByNetPieChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getUserCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "7"
		},
		success : function(data) {
			otherUserCountByNetPieChar.setOption(data, true);
			otherUserCountByNetPieChar.hideLoading();
		}
	});

}
/**
 * 按网络类型获取锁网用户数
 */
function initLockUserCountbyNetPieChar() {
	// 查询
	param.setParam();
	lockUserCountByNetPieChar.clear();
	lockUserCountByNetPieChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getUserCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "3"
		},
		success : function(data) {
			lockUserCountByNetPieChar.setOption(data, true);
			lockUserCountByNetPieChar.hideLoading();
		}
	});

}
/**
 * 按网络类型获取流量数
 */
function initAllFlowCountbyNetPieChar() {
	// 查询
	param.setParam();
	allFlowCountByNetPieChar.clear();
	allFlowCountByNetPieChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getAllCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "traffic_sum"
		},
		success : function(data) {
			allFlowCountByNetPieChar.setOption(data, true);
			allFlowCountByNetPieChar.hideLoading();
		}
	});

}



/**
 * 按网络类型获取4G用户流量
 */
function initLteFlowCountbyNetPieChar() {
	// 查询
	param.setParam();
	lteFlowChar.clear();
	lteFlowChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getFlowCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "1"
		},
		success : function(data) {
			lteFlowChar.setOption(data, true);
			lteFlowChar.hideLoading();
		}
	});

}
/**
 * 按网络类型获取3G用户数
 */
function initOtherFlowCountbyNetPieChar() {
	// 查询
	param.setParam();
	otherFlowChar.clear();
	otherFlowChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getFlowCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "7"
		},
		success : function(data) {
			otherFlowChar.setOption(data, true);
			otherFlowChar.hideLoading();
		}
	});

}
/**
 * 按网络类型获取锁网用户数
 */
function initLockFlowCountbyNetPieChar() {
	// 查询
	param.setParam();
	lockFlowChar.clear();
	lockFlowChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/terminalAnalysis/getFlowCountByPie?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param),
			"type" : "3"
		},
		success : function(data) {
			lockFlowChar.setOption(data, true);
			lockFlowChar.hideLoading();
		}
	});

}
function resetQueryForm() {
	$("#brandDiv").jqxComboBox('val', 'all');
	$('#modelDiv').jqxComboBox('clear');
	$('#queryForm')[0].reset();
}

function exportExcel() {
	$.ajax({
		type : "POST",
		url : "../../businessAnalysis/attachment/exportBigDataExcel?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"allData" : JSON.stringify(d)
		},
		success : function(data) {
			if (data.flag) {
				var url = "../../businessAnalysis/attachment/downFiles?path="
						+ data.path;
				window.location.href = url;
			} else {
				alert(data.msgs);
			}
		}
	});
}

function forwordInterfaceFailure(dateType, paramDate) {
	var url = "/kpi/interfaceFailure/index?dateType=" + dateType
			+ "&paramDate=" + paramDate + "&interfaceType=2&signalType=1";
	// window.location.href=url;
	linkTab("接口故障", url);
}

